package factory;

import java.util.ArrayList;

import processes.MachineManager;
import to.OrderTO;

public class ObserverManager {
	private static ObserverManager instance;
	private ArrayList<MachineManager> mmList = new ArrayList(); 
	private ObserverManager() {
	}
	
	public static ObserverManager getInstance(){
		if(instance==null){
			instance = new ObserverManager();
		}
		return instance;
	}
	
	public static ArrayList<MachineManager> getManagerList(){
		if(instance==null){
			return null;
		}
		return instance.mmList;
	}
	
	public void addMachineManager(MachineManager mmNode){
		mmList.add(mmNode);
	}
	
	public void notifyOrder(OrderTO order){
		System.out.println("updated order : " + order);
		for(int i=0; i<=mmList.size()-1; i++){
			mmList.get(i).notifyOrder(order);
		}
	}
	
	public void notifyFinishedOrder(OrderTO order){
		System.out.println("finished order : " + order);
		for(int i=0; i<=mmList.size()-1; i++){
			mmList.get(i).notifyFinishedOrder(order);
		}
	}
	
	public void notifyDeploy(){
		for(int i=0; i<=mmList.size()-1; i++){
			mmList.get(i).notifyDeploy();
		}
	}
}
